import { TaPost } from "../script/ajax";

// 商品接口
export const TaDataGoods = {

	// 加载分类标签
	withCate(): Promise<any> {
		return TaPost('/shop/api.goods/cate')
	},

	// 加载商品数据
	withGoods(code: string = '', sort: any = '', name: string = ''): Promise<any> {
		let data: any = {}
		if (code) data.code = code
		if (sort !== '') data.sort = sort
		if (name !== '') data.name = name;
		return TaPost('/shop/api.goods/get', data)
	},

	// 解析规格数据
	withSpecs(spec: string): string {
		let names: any[] = []
		spec.split(';;').forEach((v: string) => names.push(v.split('::').pop()))
		return names.join(' ')
	},

	// 获取商品关键词
	withSuggest(keys: string) {
		return TaPost('/shop/api.goods/hotkeys', { keys: keys })
	}
};